package org.example.redisdemo.services;

import jakarta.annotation.Resource;
import org.springframework.data.redis.connection.RedisStreamCommands;
import org.springframework.data.redis.connection.stream.RecordId;
import org.springframework.data.redis.connection.stream.StringRecord;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.Collections;

@Service
public class RedisService {

    @Resource
    private RedisTemplate redisTemplate;


    public  void set(String key, String value) {
        redisTemplate.opsForValue().set(key, value);
    }



    public void xAdd(String key ,String value) {
        StringRecord record = StringRecord.of(Collections.singletonMap(key, value)).withStreamKey("teststream");
        RecordId recordId = redisTemplate.opsForStream().add(record, RedisStreamCommands.XAddOptions.maxlen(20));
    }
}
